@using VocaDb.Web.Helpers;
@using VocaDb.Web.Models.Song;
@inherits VocaDb.Web.Code.VocaDbPage<VocaDb.Model.DataContracts.Songs.ArchivedSongVersionDetailsContract>

@{
	
    PageProperties.Title = "Revision " + Model.ArchivedVersion.Version + " for " + Model.Name;
	
	if (Model.Song != null) {
		ViewBag.Parents = new[] { 
			Html.ActionLink("Song", "Index", "Search", UrlMapper.Search.Songs(), null), 
			Html.ActionLink(Model.Song.Name, "Details", new { id = Model.Song.Id }),
			Html.ActionLink("Revisions", "Versions", new { id = Model.Song.Id }) 
		};
	} else {
		ViewBag.Parents = new[] { 
			Html.ActionLink("Song", "Index", "Search", UrlMapper.Search.Songs(), null)
		};
	}

}

@section Toolbar {
@if (Login.CanRevertEntryVersions && Model.CanBeReverted) {
	@Html.ActionLink("Revert to this version", "RevertToVersion", new { archivedSongVersionId = Model.ArchivedVersion.Id }, new { id = "revertLink", onclick = "return confirm(\"Are you sure you want to revert to this version?\");" })
}
&nbsp;
<a href="@Url.Action("ArchivedVersionXml", new { id = Model.ArchivedVersion.Id })" id="downloadXmlLink">Download XML</a>
<a href="#" id="reportEntryLink" data-bind="click: reportViewModel.show">@ViewRes.EntryDetailsStrings.ReportAnError</a>
}

@if (Model.ComparableVersions.Any()) {
	using (Html.BeginForm("ViewVersion", "Song", FormMethod.Post, new { @class = "form form-inline" })) {
		@:Compare to: @Html.DropDownListFor(m => m.ComparedVersionId, ViewHelper.CreateSelectList(Model.ComparableVersions, i => i.Id, i => i.Version + " (" + Versions.GetChangeString(i.ChangedFields) + " by " + i.AgentName + ")", Model.ComparedVersionId), new { @class = "input-xlarge", onchange = "$(this).closest('form').submit();" })
		<button type="submit" class="btn btn-primary">Compare</button>
	}
}

@ArchivedEntryHelpers.ArchivedObjectVersionProperties(Versions.CreateForSong(Model.ArchivedVersion), 
	Model.ComparedVersion != null ? Versions.CreateForSong(Model.ComparedVersion) : null)

@SongHelpers.PrintArchivedSongData(Model.Versions)

@EntryDetailsHelpers.ReportEntryVersionPopupKnockout()

@section BodyScripts {
	<script src="@Url.Content("~/Scripts/ViewModels/Song/ArchivedSongViewModel.js")"></script>
    <script type="text/javascript">

		$(function () {

            $("#revertLink").button({ icons: { primary: 'ui-icon-arrowrefresh-1-w'} });
            $("#downloadXmlLink").button({ icons: { primary: 'ui-icon-arrowthickstop-1-s' } });
            $("#reportEntryLink").button({ icons: { primary: 'ui-icon-alert'} });

            var rep = new vdb.repositories.SongRepository('@RootPath', @LanguagePreferenceInt);

			var viewModel = new vdb.viewModels.songs.ArchivedSongViewModel(@Model.Song.Id, @Model.ArchivedVersion.Version, rep);
			ko.applyBindings(viewModel);

        });

    </script>
}